package btree;


import heap.*;
import global.*;
import diskmgr.*;

public class BTHeaderPage extends HFPage{

	public BTHeaderPage(PageId pageno)
    throws ConstructPageException
    {
		super();
		try {
			SystemDefs.JavabaseBM.pinPage(pageno, this, false);
			this.dumpPage();
		} catch(Exception e)
		{
		    throw new ConstructPageException(e,"btree.BTHeaderPage(PageId pageno): pinPage failed");
		}
    }
	
	public BTHeaderPage(Page page)

	{
		super(page);
	}

	public BTHeaderPage()
    throws ConstructPageException
    {
		super();
		Page p=new Page();
		try {
			PageId pid=SystemDefs.JavabaseBM.newPage(p, 1);
			if(pid==null)
				throw new ConstructPageException("btree.BTHeaderPage(): new Page Failed");
			this.init(pid, p);
			this.setCurPage(pid);
			this.setNextPage(new PageId(-1));
			this.setPrevPage(new PageId(-1));
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
	
	public void setPageId(PageId pageno)
    throws java.io.IOException
    {
		this.setCurPage(pageno);
    }
	
	public PageId getPageId()
    throws java.io.IOException
    {
		return getCurPage();
    }
	
	
	public void set_rootId(PageId rootID)
    throws java.io.IOException
    {
		this.setNextPage(rootID);
    }
	
	public PageId get_rootId()
    throws java.io.IOException
    {
		return getNextPage();
    }


	public void set_keyType(short key_type)
    throws java.io.IOException
    {
		setSlot(1, (int)key_type, 0);

    }

	public short get_keyType()
    throws java.io.IOException
    {
		return (short)getSlotLength(1);
    }
	
	public void set_maxKeySize(int key_size)
    throws java.io.IOException
    {
		setSlot(2, key_size, 0);

    }
	
	public int get_maxKeySize()
    throws java.io.IOException
    {
		return getSlotLength(2);

    }
	
	public void set_deleteFashion(int fashion)
    throws java.io.IOException
    {
		setSlot(3, fashion, 0);
    }
	
	public int get_deleteFashion()
    throws java.io.IOException
    {
		return getSlotLength(3);

    }
	
	public void set_magic0(int magic)
    throws java.io.IOException
    {
		setSlot(4, magic, 0);
    }
	
	public int get_magic0()
    throws java.io.IOException
    {
		return getSlotLength(4);
    }
	
}
